package com.songcha.library_business.util

import android.content.Context
import android.content.Intent
import android.graphics.Color
import com.alibaba.android.arouter.launcher.ARouter
import com.songcha.library_business.R
import com.songcha.library_business.proxy.configuration.SystemConfigurationManager
import com.songcha.library_common.util.ColorUtil
import com.songcha.library_common.util.JumpUtil
import com.songcha.library_webview.ui.activity.WebViewActivity
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class BusinessJumpUtil {
    companion object{

        @JvmStatic
        fun toUserPrivacyActivity(context: Context,type:Int){
            SystemConfigurationManager.getSystemConfiguration()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    if(type==1)
                        toWebViewActivity(context,it.userProtocol,"用户协议",ColorUtil.getResourceColor(context,
                            (com.songcha.library_common.R.color.primary)))
                    else
                        toWebViewActivity(context,it.privacyPolicy,"隐私政策",ColorUtil.getResourceColor(context,
                            (com.songcha.library_common.R.color.primary)))
                },{

                })
        }

        @JvmStatic
        fun toSplashActivity(context: Context,notToMain:Boolean){
            ARouter.getInstance().build("/splash/SplashActivity")
                .withBoolean("not_to_main",notToMain)
                //.withFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME)
                .navigation()
        }

        @JvmStatic
        fun toImageActivity(url:String){
            ARouter.getInstance().build("/home/ImageActivity").withString("url",url).navigation()
        }

        @JvmStatic
        fun toARouterActivity(path:String){
            ARouter.getInstance().build(path).navigation()
        }

        @JvmStatic
        fun toWebViewActivity(context: Context, url:String,title:String="",titleColor:Int = Color.BLACK){
            if(url.isBlank()) return
            val intent= Intent(context,WebViewActivity::class.java)
            intent.putExtra("url",url)
            intent.putExtra("title",title)
            intent.putExtra("title_color",titleColor)
            context.startActivity(intent)
        }

    }
}